//
// Created by Soar Qin on 2017/8/18.
// Copyright (c) 2017 Soar Qin. All rights reserved.
//

#pragma once

namespace core::async {

struct HttpReqContext;
class Loop;

class HttpReqBase {
    DISABLE_CLASS_COPY(HttpReqBase);
public:
    explicit HttpReqBase(Loop &loop);
    virtual ~HttpReqBase();

    bool get(const std::string& url);

    inline HttpReqContext *getContext() { return context_; }

    virtual void stop();

    virtual void onProgress(int64_t curr, int64_t total, int64_t uploadcurr, int64_t uploadtotal) {}
    virtual void onData(const void *buf, size_t size) {}
    virtual void onFinished(const std::string& effurl) = 0;

protected:
    HttpReqContext *context_;
};

class HttpReqSimple: public HttpReqBase {
    DISABLE_CLASS_COPY(HttpReqSimple);
public:
    using HttpReqBase::HttpReqBase;

private:
    void onData(const void *buf, size_t size) override;

protected:
    std::string data_;
};

}
